{% load static %}

<!DOCTYPE html>
<html style="overflow-x:auto;overflow-y:auto;">
<head>
	<title>Dictionary Manage</title>
	
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="author" />
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,IE=10" />
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Cache-Control" content="no-store">
<script>var d = "";</script>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
{% include 'base.html' %}
<!-- js-->
<script type="text/javascript">

    $(document).ready(function(){
        $('input.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });


</script>
<!--js2-->
	
	
	<meta name="decorator" content="ani"/>
	
<!--js3-->
	
<script type="text/javascript">
$(document).ready(function() {
	$('#table').bootstrapTable({
			  //请求方法
				method: 'post',
				//类型json
				dataType: "json",
				contentType: "application/x-www-form-urlencoded",
                 //是否显示行间隔色
                striped: true,
                //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
                cache: false,
				//显示检索按钮
		        showSearch: true,
				//显示刷新按钮
				showRefresh: true,
				//显示切换手机试图按钮
				showToggle: true,
				//显示 内容列下拉框
				showColumns: true,
				//显示切换分页按钮
                //是否显示分页（*）  
                pagination: true, 
                
                pageList: [10, 25, 50, 100],
                //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
                url: "/system/dict/list/",
                //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
                //queryParamsType:'',   
                ////查询参数,每次调用是会带上这个参数，可自定义                         
                queryParams : function(params) {
                	var searchParam = $("#searchForm").serializeJSON();
                	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
                	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
                	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                    return searchParam;
                },
				onShowSearch: function () {
					$("#search-collapse").slideToggle();
				},
                //分页方式：client客户端分页，server服务端分页（*）
                sidePagination: "server",
                contextMenuTrigger:"right",//pc端 按右键弹出菜单
                contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
                contextMenu: '#context-menu',
                onContextMenuItem: function(row, $el){
                    if($el.data("item") == "edit"){
                    	edit(row.id);
                    } else if($el.data("item") == "delete"){
                        del(row.id);
                       
                    } 
                },
                
                columns: [{
			        checkbox: true
			       
			    }, {
			        field: 'type',
			        title: 'Type',
			        sortable:true
			    }, {
			        field: 'description',
			        title: 'Description',
			        sortable:true
			    }, {
                    field: 'operate',
                    title: 'Operation',
                    align: 'center',
                    events: {
        		        'click .view': function (e, value, row, index) {
        		        	jp.openViewDialog('View Dictionary', '/system/dict/view/?id=' + row.id,'800px', '500px');
        		        },
        		        'click .edit': function (e, value, row, index) {
        		        	jp.openSaveDialog('Edit Dictionary', '/system/dict/edit/?id=' + row.id,'800px', '500px');
        		        },
        		        'click .del': function (e, value, row, index) {
        		        	del(row.id);
        		        },
        		        'click .setDictValue': function (e, value, row, index) {
        		        	
        					$("#left").attr("class", "col-sm-6");
        					setTimeout(function(){
        						$("#right").fadeIn(500);
        					},500)
        					$("#dictTypeLabel").html(row.type);
        					$("#dictTypeId").val(row.id);
        					$('#dictValueTable').bootstrapTable("refresh",{query:{dictTypeId:row.id}})
        		        }
        		    },
                    formatter:  function operateFormatter(value, row, index) {
        		        return [
        		        	
    						'<a href="#" class="view" title="View" ><i class="fa fa-eye"></i> </a>',
    						
    						 
    							'<a href="#" class="edit" title="Edit"><i class="fa fa-edit"></i> </a>',
    						
    						 
    						    '<a href="#" class="del" title="Delete"><i class="fa fa-trash"></i> </a>',
    						
    						 
    							'<a href="#" class="setDictValue"  title="Key Value"><i class="fa fa-cog"></i> </a>'
    						
        		        ].join('');
        		    }
                }]
			
			});
		
		  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，默认关闭tab
			  $('#table').bootstrapTable("toggleView");
			}
		  
		  $('#table').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
	                'check-all.bs.table uncheck-all.bs.table', function () {
	            $('#remove').prop('disabled', ! $('#table').bootstrapTable('getSelections').length);
	            $('#edit').prop('disabled', $('#table').bootstrapTable('getSelections').length!=1);
	        });

		  $("#search").click("click", function() {// 绑定查询按扭
			  $('#table').bootstrapTable('refresh');
			});
		  $("#reset").click("click", function() {// 绑定查询按扭
			  $("#type").val("");
			  $("#description").val("");
			  $('#table').bootstrapTable('refresh');
			});
		  
	});

  function getIdSelections() {
        return $.map($("#table").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }
  
  function add(){
	  jp.openSaveDialog('add dictionary', '/system/dict/add/','800px', '500px')
  }
  
  function edit(id){
	  if(!id){
			id = getIdSelections();
		}
	  jp.openSaveDialog('edit dictionary', "/system/dict/edit/?id=" + id,'800px', '500px')
	  
  }
  function del(ids){
		if(!ids){
			ids = getIdSelections();
		}
		jp.loading();
		jp.confirm('Are you sure delete?',  function(){
     	  	$.get("/system/dict/del/?ids=" + ids, function(data){
     	  		if(data.success){
     	  			$('#table').bootstrapTable('refresh');
    	  			jp.success(data.msg);
    	  		}else{
    	  			jp.error(data.msg);
    	  		}
     	  	})
		})
  }

  function refresh(){
      $('#table').bootstrapTable('refresh');
  }
function refreshDictValue(){
    $('#dictValueTable').bootstrapTable("refresh");
}
  
  
$(document).ready(function() {
	var token = $('input[name=csrfmiddlewaretoken]').val();
	var $dictValueTable =	$('#dictValueTable').bootstrapTable({
			  //请求方法
				method: 'post',
				//类型json
				dataType: "json",
				contentType: "application/x-www-form-urlencoded",
                 //是否显示行间隔色
                striped: true,
                //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
                cache: false,    
                //是否显示分页（*）  
                pagination: false,   
                //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
                url: "/system/dict/value/list/",
                //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
                //queryParamsType:'',   
                ////查询参数,每次调用是会带上这个参数，可自定义                         
                queryParams : function(params) {
					var searchParam = $("#searchForm").serializeJSON();
                    return {dictTypeId:$("#dictTypeId").val(),csrfmiddlewaretoken : token};
                },
                //分页方式：client客户端分页，server服务端分页（*）
                sidePagination: "server",
                columns: [{
			        field: 'label',
			        title: 'Label'
			    }, {
			        field: 'value',
			        title: 'Value'
			    },{
			    	field: 'sort',
			        title: 'Sort'
			       
			    }, {
                    field: 'operate',
                    title: 'Operation',
                    align: 'center',
                    events: {
                    	 'click .edit': function (e, value, row, index) {
            		        	
                    		 jp.openSaveDialog('Edit Key Value', '/system/dict/value/form/?dictTypeId=' + $("#dictTypeId").val()+"&dictValueId="+row.id,'800px', '500px');
            		        },
        		        'click .del': function (e, value, row, index) {
        		        	
        		        	jp.confirm('Are you sure Delete?',function(){
        		        		jp.loading();
        		        		$.get('/system/dict/value/del/?dictValueId='+row.id+'&dictTypeId=' + $("#dictTypeId").val(), function(data){
  	                    	  		if(data.success){
  	                    	  			$('#dictValueTable').bootstrapTable("refresh");
  	                    	  			jp.success(data.msg);
  	                    	  		}else{
  	                    	  			jp.error(data.msg);
  	                    	  		}
  	                    	  	})
        		        	});
        		        }
        		    },
                    formatter:  function operateFormatter(value, row, index) {
        		        return [
        		        	
    						'<a href="#" class="edit" title="Edit" >[Edit] </a>',
    						
        		        	
    						'<a href="#" class="del" title="Delete" >[Delete] </a>'
    						
        		        ].join('');
        		    }
                }]
			
			});
		
		  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端
			  $('#dictValueTable').bootstrapTable("toggleView");
			}
		  
		  $("#dictValueButton").click(function(){
				
				jp.openSaveDialog('Add Key', '/system/dict/value/form/?dictTypeId=' + $("#dictTypeId").val(),'800px', '500px');
			});
		  
		  });

		
	</script>
	<style>
		#left {
			 -webkit-transition: width 0.5s;
                transition: width 0.5s;      
		}
	</style>
	

</head>
<body id="" class=""  style="">
	
	<div class="wrapper wrapper-content">
	<div class="panel panel-primary">
	<div class="panel-heading">
		<h3 class="panel-title">Dictionary List</h3>
	</div>
	<div class="panel-body">
	<div class="row">
			<div id="left" class="col-sm-12">
			<!-- 搜索 -->
				<div id="search-collapse" class="collapse">
					<div class="accordion-inner">
						<form id="searchForm"  class="form form-horizontal well clearfix" >
							{% csrf_token %}
						    <div class="col-xs-12 col-sm-6 col-md-4">
						    	<label class="label-item single-overflow pull-left" title="Type">Type：</label>
						    	<input id="type" name="type" class="form-control m-b"/>
						    </div>
						    <div class="col-xs-12 col-sm-6 col-md-4">
						    	<label class="label-item single-overflow pull-left" title="Description">Description：</label>
						   		<input id="description" name="description" class="form-control m-b"/>
						    </div>
						    <div class="col-xs-12 col-sm-6 col-md-4">
								 <div style="margin-top:26px">
								  <a  id="search" class="btn btn-primary btn-rounded  btn-bordered btn-sm"><i class="fa fa-search"></i> Query</a>
								  <a  id="reset" class="btn btn-primary btn-rounded  btn-bordered btn-sm" ><i class="fa fa-refresh"></i> Reset</a>
								</div>
						    </div>
						</form>
					</div>
				</div>

			<!-- 工具栏 -->
		    <div id="toolbar">
		    	
		    		<a id="add" class="btn btn-primary"  onclick="add()"><i class="glyphicon glyphicon-plus"></i> Add</a>
				
				
					<button id="edit" class="btn btn-success" disabled onclick="edit()">
			            <i class="glyphicon glyphicon-edit"></i> Update
			        </button>
				
				
					<button id="remove" class="btn btn-danger" disabled onclick="del()">
			            <i class="glyphicon glyphicon-remove"></i> Delete
			        </button>
				
		    </div><!-- 工具栏结束 -->
	
		    <!-- 表格 -->
		    <table id="table"
		           data-toolbar="#toolbar"
		           data-id-field="id">
		    </table>
			
		    <!-- context menu -->
		    <ul id="context-menu" class="dropdown-menu">
		        <li data-item="edit"><a>Edit</a></li>
		        <li data-item="delete"><a>Delete</a></li>
		        <li data-item="action1"><a>Cancel</a></li>
		    </ul> 
		    </div>
		    
		    <div  id="right" class="panel panel-default col-sm-6" style="display:none">
				<div class="panel-heading">
					<h3 class="panel-title"><label>Key Value List，Parent Type: </label><font id="dictTypeLabel"></font><input type="hidden" id="dictTypeId"/></h3>
				</div>
				<div class="panel-body">
				 <div id="dictValueToolbar">
					<button id="dictValueButton"  class="btn btn-outline btn-primary" title="Add Key Value"><i class="fa fa-plus-circle"></i> Add Key Value</button>
				</div>
				 <!-- 表格 -->
			    <table id="dictValueTable"
			           data-toolbar="#dictValueToolbar"
			           data-id-field="id">
			    </table>
			   
			   </div>
			</div>
			
		   </div>
		   </div>
		   </div>
	</div>
    

</body>
</html>